<?php


namespace app\http\middleware;

// 主要对外部接口限制
use app\common\ArrayObj;
use app\pxs\service\JwtService;
use think\facade\Request;

class checkOtherToken
{
    public function handle($request, \Closure $next)
    {

        $token = Request::header('token');
        if (empty($token)) {
            return pxsFailedJson("请传入正确Token", 2);
        }
        $jwtRes = JwtService::check($token);
        if (!empty($jwtRes)){
            return pxsFailedJson($jwtRes,2);
        }
        $jwtdata = JwtService::getData($token);

        if (empty($jwtdata)){
            return pxsFailedJson("token不存在~",2);
        }

        $ob = new class{};
        $ob = $jwtdata ;
        $ob["device_id"] =  get_device_type();
        $ob["user_type"] =   "user";
        $arrayobject = new ArrayObj($ob);
        $request->_user = $arrayobject;

        return $next($request);
    }
}